import {
  defineComponent,
  ref,
  onMounted,
  resolveDirective,
  withDirectives,
  openBlock,
  createElementBlock,
  unref
} from "vue";
import { j as useData, b as useProp } from "./index-CEDaTd93.js";
import { u as useEchart } from "./hooks-aBG276Pf.js";
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "StackedColumn",
  props: {
    component: {}
  },
  setup(__props) {
    const chartEl = ref(null);
    let globalOption;
    const props = __props;
    let chartData = [];
    const dataChange = (resp, _) => {
      if (resp.status === "SUCCESS") {
        chartData = resp.afterData;
        updateData(chartData);
      } else {
        updateData([]);
      }
    };
    useData(props.component, dataChange);
    const propValueChange = () => {
      updateData(chartData);
    };
    const { updateEchart, resizeHandler } = useEchart(chartEl);
    const { propValue } = useProp(props.component, propValueChange);
    onMounted(async () => {
      globalOption = getOption();
      updateEchart(globalOption);
    });
    const getOption = () => {
      const option = {
        grid: {
          top: propValue.area.areatop || "10%",
          left: propValue.area.arealeft || "3%",
          right: propValue.area.arearight || "4%",
          bottom: propValue.area.areadown || "10%",
          containLabel: true
        },
        tooltip: {
          trigger: "axis"
        },
        legend: {
          orient: propValue.legend.orient || "vertical",
          left: propValue.legend.left || "right",
          top: propValue.legend.top || "top",
          textStyle: {
            fontSize: propValue.legend.fontSize || 12
          },
          show: propValue.legend.show || false,
          data: []
        },
        title: {
          text: propValue.title.text,
          left: propValue.title.left,
          show: propValue.title.isShow,
          top: propValue.title.top,
          textStyle: {
            fontSize: propValue.title.titleSize
          }
        },
        xAxis: {
          type: "category",
          axisLabel: {
            fontSize: propValue.axis.xFontSize || 14,
            show: propValue.axis.xLableShow || false
          },
          splitLine: {
            show: propValue.axis.xLineShow || false
          },
          data: []
        },
        yAxis: {
          type: "value",
          axisLabel: {
            fontSize: propValue.axis.yFontSize || 14,
            show: propValue.axis.yLableShow || false
          },
          splitLine: {
            show: propValue.axis.yLineShow || false
          },
          max: value => {
            if (propValue.data.upperLimit === 0 || !propValue.data.upperLimit) {
              return value.max;
            } else {
              return propValue.data.upperLimit;
            }
          },
          min: () => {
            if (propValue.data.lowerLimit === 0 || !propValue.data.lowerLimit) {
              return 0;
            } else {
              return propValue.data.lowerLimit;
            }
          }
          // max: propValue.data.upperLimit,
          // min: propValue.data.lowerLimit
        },
        series: []
      };
      return option;
    };
    const updateData = resp => {
      globalOption = getOption();
      globalOption.xAxis.data = resp.xAxis;
      globalOption.legend.data = resp.legend;
      resp.legend.forEach((element, index) => {
        globalOption.series.push({
          data: resp.series[index],
          name: element,
          type: "bar",
          stack: "total",
          emphasis: {
            focus: "series"
          },
          label: {
            show: propValue.series.isLabel || false,
            fontSize: propValue.series.labeSize
          }
        });
      });
      updateEchart(globalOption);
    };
    return (_ctx, _cache) => {
      const _directive_resize = resolveDirective("resize");
      return withDirectives(
        (openBlock(),
        createElementBlock(
          "div",
          {
            ref_key: "chartEl",
            ref: chartEl
          },
          null,
          512
        )),
        [[_directive_resize, unref(resizeHandler)]]
      );
    };
  }
});
export { _sfc_main as default };
